<?php
//$Id: ISudingkeAPI.php 522 2012-08-15 09:22:00Z tomqin@gmail.com $

abstract class ISudingkeAPI{
    protected $version = '';
    protected $format;
    protected $method;

    function __construct($version, $format){
        $this->format  = $format;
        if($this->version != $version){
            $this->retMessage(false, 'The API version is not correct!');
        }
    }

    function setMethod($method){
        $this->method = $method;
    }

    function getMethod(){
        return $this->method;
    }

    function process(){
        $method = 'on'.$this->method;
        if(method_exists($this, $method)){
            $this->$method();
        }else{
            $this->retMessage(false, sprintf('The method `%s::%s` is not exists!', get_class($this), trim($method)));
        }
    }

    public function retMessage($success, $message, array $data = null){
        $arr = array(
            'success' => $success,
            'version' => $this->version,
            'message' => $message,
        );
        if($data){
            $arr += $data;
        }
        MobileApp::retArray($arr, $this->format);
    }

    public function onWaimaiList(){}
}
?>